use std::env;

use ane_cms::dao::{
    ArticleDetailVo, ArticleListVo, CategoryDetailVo, CategoryDo, CategoryVo, Manager,
};
use sea_orm::{Database, DbConn};

async fn get_db() -> DbConn {
    dotenv::dotenv().ok();
    let databaseurl = env::var("DATABASEURL").unwrap();
    Database::connect(databaseurl).await.unwrap()
}

#[tokio::main]
#[test]
async fn test_init_db() {
    let db = get_db().await;
    ane_cms::mutation::init_db(&db).await.unwrap();
}

#[tokio::main]
#[test]
async fn test() {
    let db = get_db().await;
    let s =
        ane_cms::dao::Manager::list_article::<ArticleListVo>(&db, 0, 12, None, None, None, None)
            .await
            .unwrap();
    println!("{s:?}");
}

#[tokio::main]
#[test]
async fn test_category() {
    let db = get_db().await;
    let data = CategoryDo {
        // p_id: None,
        p_id: Some(8),
        sort: Some(26),
        name: Some("sss".to_owned()),
        description: None,
        icon: None,
        alias: None,
        status: None,
    };
    // ane_cms::dao::Manager::add_category(&db, data)
    //     .await
    //     .unwrap();
    // ane_cms::dao::Manager::update_category(&db, 8, data)
    //     .await
    //     .unwrap();
    // let c = ane_cms::dao::Cms::fetch_category(&db, None).await.unwrap();
    let c = Manager::fetch_article_category::<CategoryDetailVo>(&db, 55, Some(1)).await;
    println!("{c:#?}");
}
